class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def deepestLeavesSum(self, root):
        now = [root]
        while now:
            next_list = []
            ans = 0
            for node in now:
                if node.left:
                    next_list.append(node.left)
                if node.right:
                    next_list.append(node.right)
                ans += node.val
            now = next_list
        return ans
